package org.csu.hotelsys.controller;


import org.csu.hotelsys.domain.Admin;
import org.csu.hotelsys.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/account")
@SessionAttributes({"admin"})
public class AccountController {
    @Autowired
    private AdminService adminService;



    @GetMapping("/control")
    public  String control(){
        return "index";
    }



    @RequestMapping("/login")
    public String login(Admin admin, Model model,HttpSession session){
         System.out.println(admin.getAdminname()+admin.getPassword());
         if("".equals(admin.getAdminname())|| "".equals(admin.getPassword())){
             model.addAttribute("Error","用户名或密码不能为空");
             return "index";
         }
        admin = adminService.getAdmin(admin.getAdminname(),admin.getPassword());
        if(admin == null){
            model.addAttribute("Error","用户名或密码错误");
            return "index";
        }
        return "customer/reserveMain";
    }

}
